<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_批量复核</title>
<script type='text/javascript'
      src='http://wms.ttyuncang.com/WebSpeech.js'></script>
<script type='text/javascript'
      src='${ctx}/static/js/map.js'></script>
<script type="text/javascript">
  $(function() {
	  $("#txt_taskCode").focus();
	 // WebSpeech.server = 'http://120.24.87.124/cgi-bin/ekho2.pl';
	 // WebSpeech.speak('成功');
  });
  WebSpeech.ready(function() {
	  WebSpeech.speak('听到声音了吗？');
  });
  var curTaskCode;
  var skuMap=new Map();
  function reset(){
	  $("#txt_info").html('');
	  $("#txt_sku").focus();
  }
  
  function keydown(){
	  curTaskCode='';
	  $("#msg_sku").html("");
	  $("#msg_pkg").html("");
	  $("#btn_pkg").hide();
	  $("[name='exist']").hide();
      $("[name='noexist']").show();
  }
  
  
  //验证
  function change_sku(){
  
	  var sku=$("#txt_sku").val().trim();
	  var expressNo=$("#txt_expressNo").val().trim();
	  
	  if(expressNo==''){
		  WebSpeech.speak("错误");
		  $("#msg_sku").css("color","red");
		  $("#msg_sku").html("请扫描面单号...");
		  $("#txt_expressNo").focus();
		  return;
	  }
	  
	  if(sku==''){
		  $("#msg_sku").select();
		  $("#msg_sku").focus();
		  $("#msg_sku").html("请录入SKU编号!");
	  }
	  
	  if(skuMap.get(sku) == null || skuMap.get(sku) ==0){
		  WebSpeech.speak("错误");
		  $("#txt_sku").select();
		  $("#txt_sku").focus();
		  return;
	  }else{
		 
		 WebSpeech.speak("正确，共" + skuMap.get(sku) +"件");
		 $("#txt_sku").val("");
		 $("#txt_sku").focus();
		 skuMap.remove(sku);
      }
	  
	  if(!skuMap.isEmpty()){
		  return;
	  }
	  pkg();
  }
  
  function showWorkTask(workTask){
       $("[name='exist']").show();
       $("[name='noexist']").hide();
       
       $("#taskCode").html(workTask.taskCode);
       $("#taskType").html(workTask.pickType);
       $("#customerCode").html(workTask.customerCode);
       $("#orderQty").html(workTask.orderQty);
       $("#goodsNum").html(workTask.goodsNum);
      /*  alert(workTask.createTime);
       $("#createTime").html(workTask.createTime); */
       var orderType=workTask.pickType;
       if(orderType=='single'){ 
    	   $("#taskType").html("单件");
       }else if(orderType=='multi'){
    	   $("#taskType").html("多件");
       }
       
  }
  
  function showTaskItems(taskItems){
      //订单明细
      var str='';
      skuMap=new Map();
      $.each(taskItems,function(i,taskItem){
         str+="<tr name='exist'>";
         str+="<td>"+(i+1)+"</td>";
         str+="<td>"+taskItem.taskCode+"</td>";
         str+="<td>"+taskItem.sku+"</td>";
         str+="<td>"+taskItem.num+"</td>";
         str+="<td>"+taskItem.stockCode+"</td>";
         str+="</tr>";
         skuMap.put(taskItem.sku,taskItem.num);
      });
      
      $("#taskItems").html(str);
      
 }
  
  //包装
  function pkg(){
	  var taskCode=$("#txt_taskCode").val().trim();
	  $.ajax({
			type:'post',
			url:'${ctx}/pkgTask/ajaxPkgBatch',
			data:{
				taskCode:taskCode
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
				if(msg=='success'){ 
					$("#txt_taskCode").val('');
					$("#txt_expressNo").val('');
					$("#txt_sku").val('');
					$("#txt_taskCode").focus();
					$("[name='exist']").hide();
				    $("[name='noexist']").show();
				    $("#msg_pkg").css("color","green");
					$("#msg_pkg").html("任务号("+taskCode+")包装完成.");
					$("#msg_sku").html("");
					curTaskCode='';
					WebSpeech.speak('完成');
				}
				else{
					alert("数据异常，请稍后重试...");
				}
				
				btn.attr("disabled",false);
				btn.css("class","btn-primary");
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				btn.attr("disabled",false);
				btn.css("class","btn-primary");
			}
	   });
  }
  
  
  function change_taskCode(){
	  var taskCode=$("#txt_taskCode").val().trim();
	  
	  if(taskCode==''){
		  $("#msg_sku").css("color","red");
		  $("#msg_sku").html("请扫描任务编号...");
		  $("#txt_taskCode").focus();
	  }
	  
	  
	  $.ajax({
			type:'post',
			url:'${ctx}/pkgTask/ajaxCheckTaskCode',
			data:{
				taskCode:taskCode
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
				
				if(msg=='success'){
					if(data.workTask.status!='3')
					{
						$("#msg_sku").html("此任务未拣货");
						WebSpeech.speak('未拣货');
						$("#txt_taskCode").val();
						$("#txt_taskCode").focus();
						return;
					}
					
					$("#msg_sku").css("color","green");
					/* $("#msg_sku").html("请扫描商品SKU...");
					$("#txt_sku").focus(); */
					$("#msg_sku").html("请扫描面单号...");
					$("#txt_expressNo").focus();
					
					//显示任务信息
					showWorkTask(data.workTask);
					showTaskItems(data.taskItems);
					WebSpeech.speak('成功');
				}
				else if(msg=='error'){
				
				    $("#msg_sku").css("color","red");
					$("#msg_sku").html("此任务不存在");
					
					$("#txt_taskCode").val('');
					$("#txt_taskCode").focus();
					WebSpeech.speak('不存在');
				}
				else if(msg=='type_error'){
					
				    $("#msg_sku").css("color","red");
					$("#msg_sku").html("非大促任务");
					
					$("#txt_taskCode").val('');
					$("#txt_taskCode").focus();
					WebSpeech.speak('不存在');
				}
				else if(msg=='status_error'){
					
				    $("#msg_sku").css("color","red");
					$("#msg_sku").html("此任务已包装");
					
					$("#txt_taskCode").val('');
					$("#txt_taskCode").focus();
					WebSpeech.speak('已包装');
				}else{
					$("#msg_sku").css("color","red");
					$("#msg_sku").html("任务异常，请检查...");
					
					$("#txt_taskCode").val('');
					$("#txt_taskCode").focus();
					WebSpeech.speak('异常');
				}
				
				
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
	  
  }
  
  function change_expressNo(){
	  var taskCode=$("#txt_taskCode").val().trim();
	  var expressNo=$("#txt_expressNo").val().trim();
	  
	  if(expressNo==''){
		  $("#msg_sku").css("color","red");
		  $("#msg_sku").html("请扫描面单号...");
		  $("#txt_expressNo").focus();
	  }
	  
	  
	  $.ajax({
			type:'post',
			url:'${ctx}/pkgTask/ajaxCheckExpressNo',
			data:{
				taskCode:taskCode,
				expressNo:expressNo
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
				if(msg=='success'){
					$("#msg_sku").css("color","green");
					$("#msg_sku").html("请扫描商品SKU...");
					$("#txt_sku").focus();
					WebSpeech.speak('成功');
				}
				else if(msg=='error'){
				    $("#msg_sku").css("color","red");
					$("#msg_sku").html("此面单号不存在");
					$("#txt_expressNo").val('');
					$("#txt_expressNo").focus();
					WebSpeech.speak('不存在');
				}else{
					$("#msg_sku").css("color","red");
					$("#msg_sku").html("面单号异常，请检查...");
					$("#txt_expressNo").val('');
					$("#txt_expressNo").focus();
					WebSpeech.speak('异常');
				}
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
  }
  
</script>
</head>

<body>
<section class="content">
 <div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<h3 class="box-title">批量复核(按任务)</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
    <!-- 扫描包装(预先打单) -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		 <tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">扫描单据：</td>
		    <td colspan="9">
		      <div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
			      <span class="input-group-text">任务编号:</span>
			      <input type="text" class="form-control"  id="txt_taskCode" onchange="change_taskCode();" />
		     </div>
		     </div>
		     <div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
			      <span class="input-group-text">面单号:</span>
			      <input type="text" class="form-control"  id="txt_expressNo" onchange="change_expressNo();" />
		     </div>
		     </div>
		      <span style="margin-left:12px; color: red;font-weight: bold;" id="msg_sku"></span>
		    </td>
		</tr>
		
	    <tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">扫描商品：</td>
		    <td colspan="9">
		     <div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
			      <span class="input-group-text">SKU编码:</span>
			      <input type="text" class="form-control" id="txt_sku" onchange="change_sku();" />
		     	</div>
		     </div>
		     <div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
		   		   <span class="input-group-text" style="color: red;font-weight: bold;" id="msg_pkg"></span>
		   		</div>
		   	</div>
		    </td>
		</tr>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<h3 class="box-title">任务信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
	<!-- 运单信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<tr name="noexist">
		     <td colspan="10" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		
		<thead name="exist" style="display: none;">
			<th>任务编号</th>
			<th>任务类型</th>
			<th>商家编码</th>
			<th>订单数量</th>
			<th>商品数量</th>
		</thead>
		
		<tr name="exist" style="display: none;">
		    <td id="taskCode"></td>
		    <td id="taskType"></td>
		    <td id="customerCode"></td>
		    <td id="orderQty"></td>
		    <td id="goodsNum"></td>
		  </tr>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<h3 class="box-title">任务详细信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
	<!-- 订单详细信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<tr name="noexist">
		     <td colspan="10" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		
		<thead name="exist" style="display: none;">
			<th>序号</th>
			<th>任务号</th>
			<th>SKU</th>
			<th>数量</th>
			<th>库位</th>
		</thead>
		<tbody id="taskItems"></tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
</section>	
</body>
</html>
